<?php


namespace app\index\controller;

use think\Db;

/**
 * 数据库插入相关
 * Class DbInsertTest
 * @package app\index\controller
 */
class DbInsertTest
{

    public function test_insert()
    {
        $data = ['name' => '康辉', 'age' => 40];
        Db::table('t_user')
            ->insert($data);
    }

    public function test_data_insert()
    {
        $data = ['name' => '董卿', 'age' => 30];
        Db::table('t_user')
            ->data($data)
            ->insert();
    }

    public function test_insert_get_id()
    {
        $data = ['name' => '海霞', 'age' => 35];
        $id = Db::table('t_user')
            ->insertGetId($data);
        echo $id;
    }

    public function test_insert_all()
    {
        $data = [
            ['name' => '朱军', 'age' => 45],
            ['name' => '尼戈美琪', 'age' => 40],
            ['name' => '辛巴111', 'age' => 20]
        ];
        $id = Db::table('t_user')
            ->insertAll($data,true);
        echo $id;
    }
}